<?php
//ob_start();
//session_start();
require_once 'index1.php';
include_once 'class/admin.php';
include_once 'class/staff.php';
include_once 'libs/configTest.php';


if (isset($_REQUEST['attempt']) & isset($_REQUEST['email']) & isset($_REQUEST['pw'])) {
    $email = $_REQUEST['email'];
    $pw = sha1($_REQUEST['pw']);

    $temp = new DBconfigTest();
    $user = $temp->checkAccount($email, $pw);
    if ($user) {
        if ($user->getAdminState() == 1) {
            $user->setDBTemp($temp);
            $_SESSION['admin'] = serialize($user);
            header("refresh:2; url=http://localhost:8080/admin.php");
        }else if($user->getAdminState()==0){
            $user->setDBTemp($temp);
            $_SESSION['staff'] = serialize($user);
            header("refresh:2; url=http://localhost:8080/staff.php");
        }
    } else {
        echo "<br>-------login state is bad";
        header("refresh:2; url=http://localhost:8080/");
    }
} else {
    echo "<br>-------please login first";
    header("refresh:2; url=http://localhost:8080/");
}

require_once 'index2.php';
//ob_end_flush();
?>